package com.simba.server.commands.impl.del;

import com.simba.common.command.ICommand;
import com.simba.common.database.DbOperator;
import com.simba.server.components.data.DeleteData;

public class DelSlotPackHistoryCmd implements ICommand
{
	public static final String NAME = "DelSlotPackHistoryCmd";
	private final DeleteData delInfo;
	private final String sql = "delete from tt_slot_pack_history where recordTime<? limit 10000;";

	public DelSlotPackHistoryCmd(DeleteData delInfo)
	{
		this.delInfo = delInfo;
	}

	@Override
	public String getName()
	{
		return DelSlotPackHistoryCmd.NAME;
	}

	@Override
	public Boolean run(Object params)
	{
		Boolean ret = false;

		if (!(params instanceof DbOperator))
		{
			return ret;
		}

		try
		{
			DbOperator dbOperator = (DbOperator) params;

			dbOperator.prepareStatement(this.sql);
			dbOperator.setTimestamp(1, this.delInfo.getDeleteBeforeTime());

			int delCount = dbOperator.executeUpdate();
			if (delCount > 0)
			{
				this.delInfo.setDelCount(delCount);
			}
			ret = true;
		}
		catch (Exception ex)
		{
			ret = false;
		}

		return ret;
	}
}
